<template>
  <div>
    <svg-icon v-if="flag" icon-class="fullscreen" class="mySvg" @click="screenFull" />
    <svg-icon v-else icon-class="exit-fullscreen" class="mySvg" @click="screenFull" />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  data() {
    return {
      flag: true
    }
  },
  // 开启全屏和退出全屏的方法有兼容性 需要安装 yarn add screenfull
  methods: {
    screenFull() {
      // document.documentElement.webkitRequestFullscreen() 有兼容性
      // toggle() 切换开启全屏/退出全屏
      if (screenfull.isEnabled) { // 判断浏览器是否支持开关全屏
        screenfull.toggle()
        this.flag = !this.flag
      } else {
        this.$message.info('很遗憾,您的浏览器不支持此功能')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.mySvg {
  color: #fff;
  cursor: pointer;
  font-size: 20px;
}
</style>
